import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import store from './store'


// 路由守卫
router.beforeEach((to, from) => {
    const token = localStorage.getItem('pz_token')
    if(!token && to.path !== '/login'){
        return '/login'
    }else if(token && to.path === '/login'){
        return '/'
    }else{
        return true
    }
})

const app = createApp(App)

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

// 路由
app.use(router)
// vuex
app.use(store)
app.mount('#app')